function getObjectList(url, authenticated, callback) {
	if (authenticated) {
		$.ajax({
			url : url,
			beforeSend : function(xhr) {
				xhr.setRequestHeader('Authorization', "Basic "
						+ base64encode("admin:secret"));
			},
			success : callback
		});
	} else {
		$.ajax({
			url : url,
			success : callback
		});
	}
}

function deleteObject(event, link) {
	var href = $(link).attr("href");
	$.ajax({
		url : href,
		type : "DELETE",
		beforeSend : function(xhr) {
			xhr.setRequestHeader('Authorization', "Basic "
					+ base64encode("admin:secret"));
		},
		success : function(data) {
			//TODO was machen
		}
	});
	event.preventDefault();
}

function updatedObject(event, link, redirect) {
	var href = $(link).attr("href");
	$.ajax({
		url : href,
		type : "PUT",
		success : function(data) {
			window.location.href = redirect;
		}
	});
	event.preventDefault();
}

function base64encode(string) {
	return btoa(string);
}

// html forms do not support http put or delete so we send via ajax
function submitForm(event) {
	var method = $(event.target).attr('method');
	var url = event.target.action;
	var dataObject = {};
	if (method == 'POST') {
		var data = '';
		$(event.target).find(':input').each(
				function() {
					if (this.name != undefined) {
						if (this.name != "") {
							data = data + ',"' + this.name + '":"'
									+ $(this).val() + '"';
						}
					}
				});
		data = '{' + data.substring(1) + '}';
		dataObject = JSON.parse(data);
	} else if (method == 'PUT') {
		var parameters = '';
		$(event.target).find(':input').each(
				function() {
					if (this.name != undefined) {
						if (this.name != "") {
							parameters = parameters + '&' + this.name + '='
									+ $(this).val();
						}
					}
				});
		if (url.indexOf("?") > -1) {
			url = url + parmeters;
		} else {
			url = url + '?' + parameters.substring(1);
		}
	}
	$.ajax({
		url : url,
		type : method,
		data : dataObject,
		beforeSend : function(xhr) {
			xhr.setRequestHeader('Authorization', "Basic "
					+ base64encode("admin:secret"));
		},
		success : function(data) {
			console.log(data);
		}
	});
	event.preventDefault();
}

function getURLParameter(name) {
	return decodeURI((RegExp(name + '=' + '(.+?)(&|$)').exec(location.search) || [
			, null ])[1]);
}